package com.qf.feigndemo.controller;

import com.qf.common.entity.User;
import com.qf.common.vo.ResultVo;
import com.qf.feigndemo.feignclient.ProviderFeignClient;
import com.qf.feigndemo.feignclient.RedisFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    private ProviderFeignClient providerFeignClient;

    @Autowired
    private RedisFeignClient redisFeignClient;

    @GetMapping("/test1")
    public String test1(){

        // 使用feignclient调用 微服务
        String echo = providerFeignClient.echo("Luffy");
        return echo;
    }

    @GetMapping("/test2")
    public ResultVo test2(){

        // 使用feignclient调用 微服务
        List<User> all = providerFeignClient.getAll();
        return new ResultVo(1,"ok",all);
    }

    @GetMapping("/test3")
    public ResultVo test3(){

        // 使用feignclient调用 微服务
        User user = new User(1, "zero", 12);
        user = providerFeignClient.updateUser(user);
        return new ResultVo(1,"ok",user);
    }

    @GetMapping("/test4")
    public ResultVo test4(){

        // 使用feignclient调用 微服务
        User user = providerFeignClient.deleteUser(10);
        return new ResultVo(1,"ok",user);
    }

    @GetMapping("/test5")
    public ResultVo test5(){

        // 使用feignclient调用 微服务
        ResultVo vo = redisFeignClient.vote("13355556666", "nami");
        return vo;

    }


}
